package com.boc.langxiang.presenter.adm;


import com.boc.langxiang.contract.adm.ArtistAboutContract;
import com.boc.langxiang.entity.request.AdmAboutRequest;
import com.boc.langxiang.entity.response.AdmAboutContent;
import com.boc.langxiang.entity.response.AdmAboutEntity;
import com.boc.langxiang.entity.response.BaseResponse;
import com.boc.langxiang.net.ApiService;
import com.boc.langxiang.net.HandleErrorSubscriber;
import com.boc.langxiang.net.NetClient;

import java.util.List;

import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * CreateTime: 2016-06-14上午10:40
 * Author: wjkjinke00@126.com
 * Description:
 */
public class ArtistAboutPresenter implements ArtistAboutContract.Presenter {

    private final ApiService mService;
    private ArtistAboutContract.View mView;

    public ArtistAboutPresenter(ArtistAboutContract.View view) {
        mService = NetClient.getInstance().net().create(ApiService.class);
        mView = view;
    }


    @Override
    public void admAbout(AdmAboutRequest request) {
//        mView.showLoading();
        mService.admAbout(request.params())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .unsubscribeOn(Schedulers.io())
                .subscribe(new HandleErrorSubscriber<BaseResponse<AdmAboutContent>>(mView) {
                    @Override
                    public void onSuccess(BaseResponse<AdmAboutContent> response) {
                        AdmAboutContent content = response.getContent();
                        if (content != null) {
                            List<AdmAboutEntity> admAboutEntitys = content.getRes();
                            mView.admAboutSuccess(admAboutEntitys);
                        } else {
                            mView.admAboutSuccess(null);
                        }
                    }
                });
    }
}
